package cn.huanba.service.mongo;

import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;

import java.util.List;

public interface MongoService<T> {

    /**
     * 保存数据
     * @param t
     */
    public void save(T t);
    public void remove(Query query, Class clazz);
    public List<T> findList(Query query, Class clazz);

    /**
     * 分页查询数据
     * @param query
     * @param clazz
     * @return
     */
    public List<T> page(int pageNo, int pageSize, Query query, Class clazz);

    /**
     * 查询总数
     * @param query
     * @param clazz
     * @return
     */
    public long count(Query query, Class clazz);

    /**
     * db.books.find({"bookName":"三国演义"})
     * @param clazz
     * @param <T>
     * @return
     */
    public <T> T findOne(String key, Object value, Class clazz);

    /**
     * db.books.find({"bookName":"三国演义"})
     * @param clazz
     * @param <T>
     * @return
     */
    public <T> T findOne(Query query, Class clazz);

    /**
     * db.books.update({"bookName":"三国"},{$:{"bookName":"四国"}})
     * @return
     */
    public long update(Query query, Update update, Class clazz);
}
